package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.dto.ReservationPageDto;
import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.MemberReservationCountByTimeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/member/reservation")
public class MemberReservationController extends BaseController {
    @Autowired
    private IMemberReservationService memberReservationService;

    @GetMapping("/cancelled-count")
    public R<Integer> cancelledCount() {
        Integer count = memberReservationService.cancelledCount();
        return R.ok(count);
    }

    @GetMapping("/countByTime")
    public R<List<Map<String, Integer>>> countByTime(@RequestParam Long time) {
        List<Map<String, Integer>> list = memberReservationService.countByTime(time);
        return R.ok(list);
    }
    /**
     * 新增预约
     */
    @PostMapping
    public AjaxResult add(@RequestBody ReservationDto reservationDto) {
        memberReservationService.add(reservationDto);
        return success();
    }
    /**
     * 分页查询预约
     */
    @GetMapping("/page")
    public R<TableDataInfo> list(ReservationPageDto reservationDto)
    {

        return R.ok(memberReservationService.selectReservationList(reservationDto));
    }
    /**
     * 取消预约
     */
    @PutMapping("{id}/cancel")
    public AjaxResult cancel(@PathVariable Long id) {
        memberReservationService.updateCancelStatus(id);
        return success();
    }
}
